03. Spring Boot Introduction

What is Spring Boot

What is Spring Boot Heading

In this class we are going to learn about the Spring Boot framework.

035ND C01 L02 A03 SPRINGBOOT INTRO

The Spring Boot framework is probably the most used framework for java-based microservices. Spring Boot is a good platform for Java developers to develop a stand-alone and production-grade spring application. Developers can get started with minimum configurations without the need for an entire Spring configuration setup. In a way, Spring Boot really helps you to speed up your application development without many required configuration you need for spring. I will compare these two frameworks in the next video.

What is spring boot?

QUESTION:

Frameworks

Please enter any microservice frameworks you have heard before. Does not necessarily need to be java-based.

ANSWER:

Thanks for your response.

These are the ones I came up with:

ASP.NET MVC, Django, Ruby on Rails, Laravel, AngularJS

I found this website, where they have a great explanation about the difference between Spring and SpringBoot: https://www.educba.com/spring-vs-spring-boot/

Spring Boot vs Spring Quiz

Which is a correct statement for Spring Framework?

SOLUTION: Spring framework is light-weight solution.

Spring boot vs spring Summary

So far, we have learned the differences between Spring MVC and Spring Boot. Both Spring and Spring Boot are java-based MVC frameworks, and both are popular MicroService choices. In the next video, I am going to show you how to setup the Spring Boot development environment. With it, you can find out what the spring boot structure is, and how individual components in Spring Boot work with other components.

Maven is a package management tool. You can use Maven to install packages not in Java whereas IntelliJ plugins provides core functionality of JetBrain product.

If you are not familiar with Maven, please visit https://maven.apache.org/ for more Maven installaton instruction and documents. If you are searching for a particular maven package, please visit https://mvnrepository.com/.

If you are not familiar with IntelliJ plugin, please visit https://plugins.jetbrains.com/.

  1. Make sure you have maven installed.

  2. Make sure you have installed maven intelliJ plugin.

  3. By default, we will use IntelliJ community version for this course. If you have ultimate version, you can install Spring Boot plugin. But for this course, we will use https://start.spring.io/ to create initial spring boot project.

Spring boot setup

Task Description:

Follow the instructions above and make sure Spring boot is set up.

Task List:

Task Feedback:

Great!

Create a spring boot app

Create Spring Boot HelloWorld Application

To verify you have completed your environment setup. Let’s create a simple Spring Boot project.

  • Go to https://start.spring.io/ where you can see the spring Initializer page to create spring Boot application.
  • The only thing you want to change in this form is the artifact name, you can call this “spring-boot-helloworld” in Artifact.
  • Click Generate the project and you will get a zip file named spring-boot-setup (if you called this artifact spring-boot-setup).
  • Unzip anywhere in your computer, and you can find a folder named sespring-boot-helloworld.
  • Open you IntelliJ IDE and select “Import Project” option in the welcome screen.
  • Change folder path to your spring-boot-helloworld folder, and click OK.
  • Select “Import Project from external model”, and select Maven. (if you don’t see Maven, make sure you install IntelliJ Maven plugin, link: https://www.jetbrains.com/help/idea/maven-support.html)
  • Click next.
  • Check “Import Maven projects automatically”. No other things need to be changed here. Click next.
  • Nothing needs to be changed here. Click next.
  • Make sure you select java1.8, if JDK option does not show up. You want to click the + icon and find your JDK path. If all set, click Next.
  • Nothing needs to be changed here. Click Finish.
  • IDE will take a few seconds to load all Maven packages. After that you will see the project structure.

Spring boot setup

Task Description:

Check if you completed the spring boot setup

Task List:

Task Feedback:

Great, now you have setup your spring boot hello world application.

035ND C01 L02 A3.2 CREATE SPRINGBOOT APP

Spring Boot Project Structure

035ND C01 L02 A04 SPRINGBOOT PROJECT STRUCTURE

Let’s take a look at the project you just created, and get familiar with what each file contains. The entry point for Spring boot application is a class file named Application. @SpringBootApplication is a convenience annotation that add all of the following.

  • @Configuration tags the class as a source of bean definitions for the application context.

  • @EnableAutoConfiguration tells Spring Boot to start adding beans based on classpath settings, other beans, and various property settings.

  • Normally you would add @EnableWebMvc for a Spring MVC app, but Spring Boot adds it automatically when it sees spring-webmvc on the classpath. This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet.

  • @ComponentScan tells Spring to look for other components, configurations, and services in the hello package, allowing it to find the controllers.

The main() method uses Spring Boot’s SpringApplication.run() method to launch an application. Did you notice that there wasn’t a single line of XML? No web.xml file either. This web application is 100% pure Java and you didn’t have to deal with configuring any plumbing or infrastructure.

You would notice a file under resources folder called application.properties, which is a file used to change application environment. We will talk about that in later videos. You can also use command line or YAML to change the properties configuration to run the application.

If you open the pom file, you will see two dependencies have already been added. We will use lots of this file later. Luckily, with IntelliJ, when we add a dependency in our java class, it will automatically be added in this file.

Spring Boot project structure Quiz

Which of the following options can we use to control the spring boot application we created?

SOLUTION: All of above

Lesson Summary

035ND C01 L02 A05 SPRINGBOOT SUMMARY